home *** CD-ROM | disk | FTP | other *** search
- /* Read Me for SndPlayDoubleBuffer
-
- --New--
-
- Now version 1.1.1
- Fixed IMA random access bug that caused grabage playback.
- Updated pause/resume code to use siRateMultiplier which is Carbon compatible,
- instead of using getRateCmd/rateCmd which are not Carbon compatible.
-
- Has been updated with some bug fixes and now is a Metrowerks Pro 5 project.
-
- --Goal of this sample--
-
- The primary purpose of this sample code is to show developers how to use SndPlayDoubleBuffer
- to play AIFF, WAVE, and .au files asynchronously from disk.
-
- To this end this sample can be used to show you how to:
-
- 1) parse an AIFF, 'snd ' resource, WAVE, or .au header
- 2) use PBReadAsync() at interrupt time
- 3) munge AIFF, WAVE, and .au data into a form the Sound Manager can play
- 4) set up the sound header to play compressed and uncompressed sounds
- 5) instantly (well, really quickly) pause a sound
- 6) stop a sound so you can play from some other part of the sound
- 7) make it sound like you are playing a sound backwards
- 8) use completion routines
- 9) have fun with sounds
-
-
- --Features--
-
- SimpleApp
-
- This code was developed using fellow DTS engineer (and really cool guy) Matt Mora's SimpleApp
- framework.
-
- This simple framework hides the dirty work of the Mac interface allowing me (and you) to
- concentrate on the code that is actually doing the interesting work.
-
- AIFC
- ----
-
- It can play AIFC files compressed with µlaw, IMA, MACE 3:1 and MACE 6:1, it should be able to
- play other formats if the proper decompressor is installed, but I have only tested with these
- four decompressors.
-
- IMA is a run length compression, and as such you cannot play an IMA compressed sound backwards
- using the simple techniques I use in this example. When doing random access in an IMA file,
- it is very important to always start playing at a frame boundary, because this contains the
- start information (basically the information that would have been generated if you played
- the file from the start until this frame). Fixed a bug that was causing the file to not play
- at the beginning of a frame and therefore play gargbage.
-
- AIFF
- ----
-
- It can play all AIFF files (that I know of) without a problem.
-
- 'snd ' resources
- ----------------
-
- It can play all the 'snd ' resources that I have seen. I have not done extensive testing
- on these yet, but they work well enough so far. I would like to add the ability to play
- all the 'snd ' resources inside of a resource file, but currently it only plays the first
- 'snd ' resource that it finds.
-
- It does not play 'snd ' resources that are not sampled-sound data, and it does not play
- 'snd ' resources that have multiple commands (i.e. multiple tracks), but I haven't seen
- any of these files to test with either.
-
- Playing a 'snd ' resource isn't as easy at would seem. Since this is a SndPlayDoubleBuffer()
- example I am not reading in the entire 'snd ' resource into memory as some other examples do.
- Since I have to fill SndPlayDoubleBuffer() buffers' at interrupt time, using the Resource
- Manager is out as well. I have written some _VERY_ basic functions that will open a resource
- fork, read in the header, look around and get the information I need. In this way I am able
- to use PBReadAsync() at interrupt time to read more of the 'snd ' resource.
-
- If you wish to use this resource code, feel free, but make sure you test it thoroughly. It
- works for me, but I can't say that it does everything, or that it does what it does, in all
- cases, correctly.
-
- .snd and .au files
- ------------------
-
- I have added Sun/NeXT .snd support (better known as .au sounds). Currently it can play
- 8 and 16 bit linear (non-compressed) sounds and µlaw compressed files. The other file
- formats don't seem to be too popular (I haven't been able to find one), and it doesn't
- look like the Sound Manager would support them (like 24 and 32 bit linear) even if I found
- them.
-
- WAVE
- ----
-
- It can play PCM (Pulse Code Modulation) and µlaw WAVE files, it can not play ADPCM or IMA
- compressed WAVE files. IMA compressed WAVE files have a different data stream than an IMA
- compressed AIFF file and the IMA decompressor cannot handle it. I do not think I will ever
- be able to make IMA compressed WAVE files play without a new IMA decompressor that can
- handle this different format.
-
- The endian conversion code has been written in C and both 68K and PowerPC assembly (because
- I wanted to) so WAVE files will work on both 68K and PPC Macs, but they should require less
- interrupt resources on a Power Mac because the PPC assembly makes use of the (really cool)
- store byte reversed command to make the processor do all the real endian conversion. Using
- this command the assembly version of the routines are about the same size, or smaller than
- their C versions. I have not unrolled the PPC assembly because I didn't feel there was too
- much speed to be gained (though I did no actuall testing). This is left as an exercise for
- the reader (I've always wanted to say that).
-
- Note:
- If you do random access inside of a WAVE file you may get garbage played for an instant.
- I have not tracked down where this is coming from, and it doesn't happen all the time. I'm
- working on finding the cause of this.
-
-
- --Background--
-
- When I first started this sample I was hoping for something similar to MoreFiles, well that
- didn't happen. But the routines in DoubleBufferFromFile.c, Private_DBFFFunctions.c,
- and Interrupt_Routines.c are still pretty useful. I tried to make them as simple and self-
- sufficient possible. You will find, however, that it is a somewhat complicated process to
- fill in the data required to start playing an AIFF, 'snd ' resource, WAVE, or .au file so
- those routines work more as a package, but I think it is a good start.
-
- I hope to have made the code largely self explanitory, with comments where necessary.
-
- As always, I welcome your feedback (good or bad). I can be reached at mcookson@apple.com.
- Please let me know what you find useful, what you find not useful, and what you would like
- to see in a future example of this type.
-
-
- --Known bugs--
-
- The only bug that I am aware of is the problem with the random WAVE garbage.
-
-
- --Fixed bugs--
-
- Fixed a bug that was causing the file to not play at the beginning of a frame and therefore
- play gargbage in IMA compressed AIFF files. This fix may help other sounds to play correctly
- when doing random access, but I have not tested that.
-
- Fixed a bug where I wasn't adding the last partial buffer into the total number of buffers
- needed to play a sound. This would make the scroll bar off by one, and if the sound only
- required one partially full buffer it thought there were zero buffers and the scroll bar
- and buttons were left in a bad state.
-
- Figured out where the length of a WAVE file really is which fixed the problem of garbage
- playing at the end of WAVE file (since non-wave data can follow the sound).
-
- Fixed a bug in the initialization code that seemed to only cause an internal consistency
- error on 68K Macs.
-
-
- --New features--
-
- Added 'wav ' as a file type to look for sounds in.
-
- Added support for Macintosh Easy Open and an 'open' resource.
-
- Added a 'vers' resource and some file icons for the application.
-
-
- --Disclaimer--
-
- The Sound Manager currently does not directly support WAVE or .au/.snd files like it does
- 'snd ' and AIFF/AIFC files. Sound Manager 3.2 does have an endian decompressor for WAVE
- files, but I do not use it. The Sound Manager does not directly read or parse .au/.snd
- or WAVE file's headers. The code I have has been written based on the file format information
- that I have found on World Wide Web and the few files that I have been able to make or
- find. This code is probably no where near complete, make sure you test it with the sounds
- you want to play to make sure that it works before you include this code in a real product.
-
-
- Happy coding,
- Mark Cookson
- Developer Technical Support
- Apple Computer, Inc.
-
- */